package main

import (
	"fmt"

	"github.com/barkimedes/go-deepcopy"
)

func testCopy(s []int) {
	fmt.Printf("s %v, %p, %p, %d, %d\n", s, &s, &s[0], len(s), cap(s))
}

func main() {

	// Go 默认采用浅 copy
	s1 := []int{1, 3, 5}
	fmt.Printf("s1 %v, %p, %p, %d, %d\n", s1, &s1, &s1[0], len(s1), cap(s1))
	s2 := s1
	fmt.Printf("s2 %v, %p, %p, %d, %d\n", s2, &s2, &s2[0], len(s2), cap(s2))
	testCopy(s1)

	// 深 copy，库
	x, err := deepcopy.Anything(s1) // []int []string
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~")
	if v, ok := x.([]int); ok {
		fmt.Printf("%T %[1]v\n", v)
		fmt.Printf("x %v, %p, %p, %d, %d\n", x, &x, &v[0], len(v), cap(v))
	} else {
		fmt.Println("断言为[]int失败")
	}
}
